<template>
  <div class="pdf">
    <div class="pdf-head">
      <div class="pdf-head-left">
        <slot name="pdf-head-left"></slot>
      </div>
      <div class="pdf-head-right">
        <slot name="pdf-head-right">
          <span @click="changePdfBodyStatus">{{
            detailBody ? "展开" : "收起"
          }}</span>
        </slot>
      </div>
    </div>
    <div ref="pdfBodyContent" class="pdf-body" :style="{ height: detailBody ? '0' : height+'px' }">
      <div >
        <slot name="pdf-body"></slot>
      </div>
    </div>
    <div class="pdf-foot"></div>
  </div>
</template>

<script setup lang="ts">
import { computed, ref } from "vue";

const detailBody = ref<boolean>(false);
const pdfBodyContent = ref<HTMLDivElement | null>(null)

const height = computed(()=>pdfBodyContent.value?.getBoundingClientRect().height)

// 修改pdfItem的body的升起/关闭状态
const changePdfBodyStatus = () => {
  detailBody.value = !detailBody.value
}
</script>

<style lang="scss" scoped>
.pdf {
  background-color: rgba(255, 255, 255, 0.8);
  width: 60%;
  margin: 0px auto 30px;
  box-shadow: 0 0 10px 0px rgba(0, 0, 0, 0.2);
  .pdf-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 40px;
    border-bottom: 1px solid rgba(30, 30, 30, 0.1);
    padding: 0 30px;
    .pdf-head-left {
      font-weight: 300;
      font-size: 20px;
      color: rgba(20, 20, 20, 0.7);
    }
    .pdf-head-right {
      font-weight: 400;
      font-size: 13px;
      color: rgba(100, 100, 100, 0.5);
      span {
        transition: all 0.2s;
        &:hover {
          color: rgba(0, 0, 0);
        }
      }
    }
  }
  .pdf-body {
    overflow: auto;
    border-bottom: 1px solid rgba(30, 30, 30, 0.1);
    transition: all 0.3s;
    div {
      margin: 10px 8px;
    }
  }
  .pdf-foot {
    height: 30px;
  }
}
</style>
